<?php
/**
 * @version		1.0.0
 * @category	Anahita Social Simple Blogs
 * @copyright	Copyright (C) 2008 - 2010 rmdStudio Inc. and Peerglobe Technology Inc. All rights reserved.
 * @license		GNU GPLv3 <http://www.gnu.org/licenses/gpl-3.0.html>
 * @link     	http://www.anahitapolis.com
 */

/**
 * Blog Post Controller
 *
 */
class ComQuestionsControllerQuestion extends AnSekitMediumController
{
	
    /**
     * Initializes the options for the object
     *
     * Called from {@link __construct()} as a first step of object instantiation.
     *
     * @param 	object 	An optional KConfig object with configuration options.
     * @return 	void
     */
	protected function _initialize(KConfig $config)
	{	
		parent::_initialize($config);
	}
		
	/**
	 * Browse a list of posts
	 * 
	 * @see AnSekitController::_actionBrowse()
	 */
	public function _actionBrowse($context)
	{
	  $data 	= $context->data;
	  $actor   	= $data->actor; //the actor referenced by oid
	  
	  /*
	   * you can sort, limit the actor questions
	   * $actor->questions->limit(x)->sort(); 
	   */
	  
	}
	
	/**
	 * Adds a post
	 *
	 * @param KCommandContext $context
	 */
	protected function _actionAdd($context)
	{
		$data  = $context->data;
		$actor = $data->actor;
		$question = $actor->questions->add(array('title'=>$data->question, 'author'=>$this->getViewer()));
		$question->application = $this->getApplication();
		$data->append(array('choices'=>array()));
		foreach($data->choices as $choice) {
			$choice = $question->choices->add(array('title'=>$choice));
		}
		
		return $question;
	}
}
 